<template>
	<div>
		<div class="app_alert">
			<div class="header_app_logo" @click="download">
				<img
					src="https://res.metaera.hk/resources/assets/images/appdownload.png"
				/>
			</div>
		</div>

		<div
			style="
				position: absolute;
				top: 0;
				width: 100%;
				height: 100%;
				background-color: #000000ca;
				z-index: 9999;
			"
			@click="hideAlert"
			v-if="olead == true"
		>
			<img
				style="width: 100%"
				src="https://res.metaera.hk/resources/assets/images/aboutus/download_alert1.png"
				alt=""
			/>
		</div>
	</div>
</template>

<script>
export default {
	name: "",
	created() {},
	data() {
		return {
			token: 0,
			active: 0,
			olead: false,
		};
	},
	methods: {
		hideAlert() {
			this.olead = false;
		},
		download() {
			// 获取当前页面的路径部分
			const path = window.location.pathname;
			console.log("Path:", path);

			const parts = path.split("/");
			const id = parts[parts.length - 1];

			let ua = navigator.userAgent.toLowerCase();
			//ios终端
			let isiOS = !!ua.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
			if (ua.match(/MicroMessenger/i) == "micromessenger") {
				this.olead = true;
			} else {
				if (path.includes("/contents/") || path.includes("/news/")) {
					var url = "metaeraapp://metaera.hk/wz?id=" + id;
					window.location.href = url; //打开调整的地址
				} else if (path.includes("/events")) {
					var url = "metaeraapp://metaera.hk/event?id=" + id;
					window.location.href = url; //打开调整的地址
				} else {
					var url = "metaeraapp://metaera.hk/home";
					window.location.href = url; //打开调整的地址
				}
				console.log(url);

				var that = this;
				setTimeout(function () {
					that.$router.push({
						path: "/download",
					});
				}, 1000);
			}
		},
		gotoDownLoad() {
			this.$router.push({
				path: "/download",
			});
		},
	},
};
</script>

<style scoped>
.app_alert {
	align-items: center;
	text-align: center;
	align-content: center;
	width: 100%;
	height: 60px;
	background: rgba(0, 0, 0, 0);
	opacity: 1;
	z-index: 999;
	position: fixed;
	bottom: 20px;
	z-index: 999;
}
.header_app_logo img {
	width: auto;
	height: 30px;
}
</style>
